const GET = 'GET';
const POST = 'POST';
const PUT = 'PUT';
const FORM = 'FORM';
const DELETE = 'DELETE';

// const baseURL = 'https://www.xianzl.co/zl';  //240
const baseURL = 'https://www.sxjxasmyx.com/zl';

// const  websocketUrl = '47.99.35.240:80';  //240

const  websocketUrl = 'www.sxjxasmyx.com';



function request(method, url, data, header) {
    return new Promise(function (resolve, reject) {
        let head = {
            'Content-type': header ? header : 'application/x-www-form-urlencoded',
            'token': wx.getStorageSync('token') ? wx.getStorageSync('token') : ''
        }
        wx.request({
            url: baseURL + url,
            method: method,
            data: method === POST ? data : data,
            header: head,
            success(res) {
                if (res.data.code == 0 || res.data.code == 200) {
                    resolve(res.data);
                } else if (res.data.code == 401) {
                    wx.removeStorage({
                      key: 'token',
                    })
                    wx.removeStorage({
                        key: 'userId',
                      })
                      wx.removeStorage({
                        key: 'gongHao',
                      })

                    wx.showToast({
                        title: 'token失效，请重新登录',
                        icon: 'none',
                        duration: 1000,
                    })
                    setTimeout(() => {
                        wx.reLaunch({
                            url: '../login/login'
                        })
                    }, 1000);
                } else {
                    reject(res.data);
                }
            },
            fail(err) {
                reject(err)
            }
        })
    })
}

const API = {
    getProjectType: (data) => request(POST, `/sys/tprojecttype/list`, data),
    getProjectList: (data) => request(POST, `/sys/tproject/list`, data),
    login: (data) => request(POST, `/sys/login`, data, 'application/json'),
    jishiStatus: (data) => request(POST, `/jishiMainPage/stateQuery`, data),
    getKaoQing:(data) => request(POST, `/jishi/kaoqin/getStaffShiftList`, data,'application/json'),
    getDakaShiJian: (data) => request(POST, `/jishi/kaoqin/list`, data,'application/json'),
    getShopInfo: (data) => request(POST, `/tFenDian/list`, data,'application/json'),
    daka: (data) => request(POST, `/jishi/kaoqin/save`, data,'application/json'),
    roomList: (data) => request(POST, `/app/troom/roomList`, data,'application/json'),
    jishiWorkingInfo: (data) => request(POST, `/jishiMainPage/jishiWorkingInfo`, data,),
    getProjectInfo: (data) => request(POST, `/sys/tproject/info/${data}`),
    getLiuShui: (data) => request(POST, `/tOpenRoom/getLiuShui`,data,'application/json'),
    tiaoPai: (data) => request(POST, `/tOpenRoom/tiaoPaiJiShi`,data,'application/json'),    
    xiaZhong: (data) => request(POST, `/tOpenRoom/xiaZhong`,data,'application/json'),    
    getJIShiInfo:(data) => request(POST, `/sys/tstaff/info/${data}`,data),    
    getSysMsg: (data) => request(POST, '/jishi/sysmessage/list', data, 'application/json'),
    getTuiKa: (data) => request(POST, '/jishi/membercard/list', data, 'application/json'),
    getDutyMsg: (data) => request(POST, '/jishi/jishifuwu/list', data, 'application/json'),
    getYuyueMsg: (data) => request(POST, '/jishi/yuding/list', data, 'application/json'),
    shangZhong: (data) => request(POST, '/tOpenRoom/shangZhong', data, 'application/json'),
    addFeiZyGoods: (data) => request(POST, '/jishiMainPage/addFeiZyGoods', data, 'application/json'),
    getGoods: (data) => request(POST, '/tOrderGoods/list', data, ),
    genHuanXiangMu: (data) => request(POST, '/tOpenRoom/genHuanXiangMu', data,'application/json' ),
    getDangTianYeJi: (data) => request(POST, '/tOpenRoom/getDangTianYeJi', data,'application/json' ),
    changePassword: (data) => request(POST, '/sys/user/password', data,'application/json' ),
    getYuyueData: (data) => request(POST, '/app/troomyuding/list', data,'application/json' ),
    keRenDengDailist: (data) => request(POST, '/tOpenRoom/keRenDengDailist', data,'application/json' ),
    keRenDengDelete: (data) => request(POST, '/tOpenRoom/keRenDengDelete', data,'application/json' ),
    getUserId: (data) => request(POST, `app/troomyuding/getByGongHao?gonghao=${data}`,'application/json' ),
    addproject: (data) => request(POST, '/tOrderGoods/insert', data,'application/json' ),
    changeProject: (data) => request(POST, `/sys/tproject/listByStaffId/${data}`, data,'application/json' ),
    queryJiaZhongProject: (data) => request(POST, `/tOpenRoom/queryJiaZhongProject`, data,'application/json' ),
    jiaZhongBaoZhong: (data) => request(POST, `/tOpenRoom/jiaZhongBaoZhong`, data,'application/json' ),
    
};
module.exports = {
    API: API,
    baseURL,
    websocketUrl
}